#include "CIcon.h"

CIcon::CIcon()
{

}
CIcon::CIcon(std::string path)
{
	if(path != "")
	{		
		if(!iconTexture.loadFromFile(path))
		{
			LOG(ERROR) << "Cannot load texture from that path: " << path;
		}else
		{
			LOG(INFO) << "Texture loaded successfully: " << path;
		}
	}else
	{
		LOG(WARNING) << "Icon load: The path is empty";
	}
	iconSprite.setTexture(iconTexture);
}
void CIcon::setPosition(int x, int y)
{
	iconSprite.setPosition(x,y);
}
void CIcon::setScale(float x, float y)
{
	iconSprite.setScale(x,y);
}
void CIcon::update()
{
	
	actualScale = iconSprite.getScale();
	actualPosition = iconSprite.getPosition();
}
sf::Vector2f CIcon::getPosition()
{
	return iconSprite.getPosition();
}
void CIcon::setPosition(sf::Vector2f newPosition)
{
	this->actualPosition = newPosition;
}

void CIcon::setTexture(std::string stringPath)
{
	if(stringPath != "")
	{		
		if(!iconTexture.loadFromFile(stringPath))
		{
			LOG(ERROR) << "Cannot load texture from that path: " << stringPath;
		}else
		{
			LOG(INFO) << "Texture loaded successfully: " << stringPath;
		}
	}else
	{
		LOG(WARNING) << "Icon load: The path is empty";
	}
	iconSprite.setTexture(iconTexture);
}
void CIcon::draw(sf::RenderWindow &render)
{
	render.draw(iconSprite);
}
void CIcon::setTexture(std::string stringPath, int x, int y, int width, int height)
{
	if(x >=0 && y >=0 && width >=0 && height >= 0)
	{
		sf::IntRect tempRectangle(x,y,width,height);
		if(stringPath != "")
		{		
			if(!iconTexture.loadFromFile(stringPath, tempRectangle))
			{
				LOG(ERROR) << "Cannot load texture from that path: " << stringPath;
			}else
			{
				LOG(INFO) << "Texture loaded successfully: " << stringPath;
			}
		}else
		{
			LOG(WARNING) << "Icon load: The path is empty";
		}
		
		iconSprite.setTexture(iconTexture);
	}
	
}
CIcon::~CIcon()
{

}